import { ChartDefinition } from "../../charts/DashboardCharts"
import { computed, ComputedRef } from "vue"

const tests = ["inEditorCodeGeneration_function", "inEditorCodeGeneration_all", "getAvailableProfiles", "documentation_generation_calculator_sum"]
const defaultMetric = "success_rate"
const timingMetric = "response_time#mean_value"
const nameSuggestTests = [
  "java_name_suggest_PsiAnnotation",
  "java_name_suggest_PsiClass",
  "java_name_suggest_PsiVariable",
  "java_name_suggest_PsiField",
  "java_name_suggest_PsiMethod",
]
const testGenerationTests = ["test_generation_add_tests: default", "test_generation_new_tests: default"]

export function toSeparateCharts(tests: string[]): ComputedRef<ChartDefinition[]> {
  return computed(() => tests.map((value) => toChartDefinition(value)))
}

export function toOneCharts(label: string, tests: string[], metric: string): ComputedRef<ChartDefinition[]> {
  return computed(() => [toCombineChartDefinition(label, tests, metric)])
}

export const testProjects = toSeparateCharts(tests)
export const nameSuggestProjects = toOneCharts("Name suggest", nameSuggestTests, defaultMetric)
export const timingProjects = toOneCharts("Responses", [...nameSuggestTests, ...tests], timingMetric)
export const testGenerationPassedProjects = toOneCharts("Test generation", testGenerationTests, "Passed Rate")
export const testGenerationCompilationProjects = toOneCharts("Test generation", testGenerationTests, "Compilation Rate")
export const testGenerationPsiValidProjects = toOneCharts("Test generation", testGenerationTests, "Psi Valid Rate")
export const testGenerationCreditAvgProjects = toOneCharts("Test generation", testGenerationTests, "Credits Cost Avg")
export const testGenerationQuotaLeftProjects = toOneCharts("Test generation", testGenerationTests, "QuotaLeft")

function toChartDefinition(test: string): ChartDefinition {
  return {
    labels: [test + " (" + defaultMetric + ")"],
    measures: [defaultMetric],
    projects: [test],
  }
}

function toCombineChartDefinition(label: string, tests: string[], metric: string): ChartDefinition {
  return {
    labels: [label + " (" + metric + ")"],
    measures: [metric],
    projects: tests,
  }
}
